local more1__beijia = fk.CreateSkill{
  name = "more1__beijia",
  tags = { Skill.Compulsory },
  dynamic_desc = function(self, player)
    if player:getMark("more1__chenqing") == 0 then
      return "more1__beijia"
    else
      return "more1__beijia1"
    end
  end,
}
Fk:loadTranslationTable{
  ["more1__beijia"] = "悲笳",
  [":more1__beijia"] = "韵律技，平：你可以将一张牌当任意锦囊牌(每回合每种牌名限一次)使用；"..
  "仄：你可以将一张牌当任意基本牌使用或打出(不计入次数限制且无距离限制)。"..
  "若你发动此技能时与本回合上一次发动技能时的韵律状态相同，此技能本回合失效。"
  .."<br>转韵：你的手牌数发生变化时，与本回合的手牌数皆不相同。",
  ["@$more1__beijia-turn"] = "悲笳",
  [":more1__beijia1"] = "韵律技，平：你可以将一张牌当任意锦囊牌使用(每回合每种牌名限一次)；仄：你可以将一张牌当任意基本牌使用或打出(不计入次数限制且无距离限制)。"..
  "若你发动此技能时与本回合上一次发动技能时的韵律状态相同，此技能本回合失效。",
  ["#more1__beijia-level"] = "悲笳（平）：你可将一张牌当任意普通锦囊牌使用",
  ["#more1__beijia-oblique"] = "悲笳（仄）：你可将一张牌当任意基本牌使用或打出",
  ["$more1__beijia1"] = "塞外青鸟匿，不闻折柳声。",
  ["$more1__beijia2"] = "向晚吹霜笳，雪落白发生。",
  

}
local miniUtil = require "packages/mini/mini_util"

more1__beijia:addEffect("viewas", {
  anim_type = "control",
  card_num = 1,
  pattern = ".",
  handly_pile = true,
  prompt = function(self, player)
    if player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYang then
      return "#more1__beijia-level"
    else
      return "#more1__beijia-oblique"
    end
  end,
  interaction = function(self, player)
    local all_names = Fk:getAllCardNames(player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYang and "t" or "b")
    if player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYang then
      table.insert(all_names, "unexpectation")
      table.insert(all_names, "drowning")
    end
    local names = player:getViewAsCardNames(more1__beijia.name, all_names,nil, player:getTableMark("@$more1__beijia-turn"))
    if #names > 0 then
      return UI.CardNameBox { choices = names, all_choices = all_names, default_choice = "AskForCardsChosen" }
    end
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    return true
  end,
  card_filter = function(self, player, to_select, selected)
    if #selected == 0 and Fk.all_card_types[self.interaction.data] ~= nil then
      return true
    end
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 or Fk.all_card_types[self.interaction.data] == nil then return end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = more1__beijia.name
    c:addSubcard(cards[1])
    return c
  end,
  after_use = function(self, player)
    local room = player.room
    player.room:addPlayerMark(player,"more1__sifu_damage")
    if player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYang then
      room:setPlayerMark(player,"more1__beijia-turn", 1)
    elseif player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYin then
      room:setPlayerMark(player,"more1__beijia-turn", 2)
    end
  end,
  before_use = function(self, player, use)

    local room = player.room
    if player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYang and use.card.type == Card.TypeTrick then
      player.room:addTableMark(player, "@$more1__beijia-turn", use.card.trueName)
    end
    if (player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYang and player:getMark("more1__beijia-turn") == 1) or
    (player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYin and player:getMark("more1__beijia-turn") == 2) then
      room:invalidateSkill(player, more1__beijia.name, "-turn")
    end
  end,
})

more1__beijia:addEffect(fk.AfterCardsMove, {
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(more1__beijia.name) then
      for _, move in ipairs(data) do
        if (move.to == player and move.to.phase ~= Player.Draw) or (move.from == player and move.from.phase ~= Player.Draw) then
            return player:getMark("more1__beijia"..player:getHandcardNum().."-turn") == 0 and player:getMark("more1__chenqing") == 0
          end
        end
      end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "more1__beijia"..player:getHandcardNum().."-turn", 1)
    miniUtil.changeRhyme(room, player, more1__beijia.name)
  end,
})

more1__beijia:addEffect(fk.AfterSkillEffect, {
  can_refresh = function(self, event, target, player, data)
    return player:hasSkill(more1__beijia.name) and data.skill.name == "more1_sifu"
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    miniUtil.changeRhyme(room, player, more1__beijia.name)
  end,
})


more1__beijia:addEffect("targetmod", {
  bypass_distances = function(self, player, skillName, card)
    return card and table.contains(card.skillNames, more1__beijia.name) and card.type == Card.TypeBasic and player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYin 
  end,
  bypass_times = function (self, player, skill, scope, card, to)
    return card and table.contains(card.skillNames, more1__beijia.name) and card.type == Card.TypeBasic and player:getSwitchSkillState(more1__beijia.name, false) == fk.SwitchYin 
  end,
})





return more1__beijia